package com.supinfo.sun.sungamers.person;

import java.io.Serializable;
import java.util.Date;

import com.supinfo.sun.sungamers.beans.Address;
import com.supinfo.sun.sungamers.enums.Sex;

/**
 * @author Liu, Bing(Locke)
 * @since 2011-04-05
 * @version 0.3
 */
public class Person implements Comparable<Person>, Serializable {
	
	private int id;

	private String firstName;

	private String lastName;

	private Address address;

	private Sex sex;

	private Date birthDate;

	public Person() {
	}

	public Person(String firstName, String lastName, Date birthDate) {
		this.firstName = firstName;
		this.lastName = lastName;
		this.birthDate = birthDate;
	}
	
	public Person(int id, String firstName, String lastName, Date birthDate) {
		this(firstName, lastName,birthDate);
		this.id = id;
	}
	
	public Person(int id, String firstName, String lastName, Sex sex) {
		this.id = id;
		this.firstName = firstName;
		this.lastName = lastName;
		this.sex = sex;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public Address getAddress() {
		return address;
	}

	public void setAddress(Address address) {
		this.address = address;
	}

	public Sex getSex() {
		return sex;
	}

	public void setSex(Sex sex) {
		this.sex = sex;
	}

	public Date getBrithDate() {
		return birthDate;
	}

	public void setBrithDate(Date brithDate) {
		this.birthDate = brithDate;
	}

	public int compareTo(Person p2) {
		if (!firstName.equals(p2.getFirstName())) {
			int first = firstName.compareTo(p2.getFirstName());
			return first != 0 ? first : firstName.compareTo(p2.getFirstName());
		} else {
			if (!lastName.equals(p2.getLastName())) {
				int last = lastName.compareTo(p2.getLastName());
				return last != 0 ? last : lastName.compareTo(p2.getLastName());
			} else {
				int date = birthDate.compareTo(p2.getBrithDate());
				return date != 0 ? -date : birthDate.compareTo(p2.getBrithDate());
			}
		}
	}
}
